package com.sky.zzh.devicemanager;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

import com.sky.widget.SHToast;
import com.sky.zzh.BaseFragment;
import com.sky.zzh.R;
import com.sky.zzh.util.CommonUtil;
import com.sky.zzh.view.SHEditTextNoClear;
import com.zbar.lib.CaptureActivity;
/**
 * 添加设备名称
 * @author skypan
 *
 */
public class AddNameFragment extends BaseFragment {

	private Button mBtnBack,mBtnScan;
	private SHEditTextNoClear mEtDeviceName;
	
	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onViewCreated(view, savedInstanceState);
		mBtnBack = (Button) view.findViewById(R.id.btn_back);
		mBtnScan = (Button) view.findViewById(R.id.btn_scan);
		mEtDeviceName = (SHEditTextNoClear) view.findViewById(R.id.et_device_name);
		setListeners();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_add_name, container, false);
		return view;
	}

	private void setListeners(){
		mBtnBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				getActivity().finish();
			}
		});
		
		mBtnScan.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(CommonUtil.isEmpty(mEtDeviceName.getText().toString().trim())){
					SHToast.showToast(getActivity(), "请输入设备名称");
					return;
				}
				Intent intent = new Intent(getActivity(),CaptureActivity.class);
				intent.putExtra("des", mEtDeviceName.getText().toString().trim());
				startActivity(intent);
				getActivity().finish();
			}
		});
	}
}
